package com.weiyun.notebook.Database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.weiyun.notebook.Dao.NoteDao
import com.weiyun.notebook.Entity.Note

@Database(version = 1, entities = [Note::class])
    abstract class AppDatabase : RoomDatabase() {
        abstract fun NoteDao(): NoteDao

        companion object {
            private var instance: AppDatabase? = null

            @Synchronized
            fun getDatabase(context: Context): AppDatabase {
                instance?.let {
                    return it
                }
                return Room.databaseBuilder(
                    context.applicationContext,
                    AppDatabase::class.java, "app_database"
                )
                    .build().apply {
                        instance = this
                    }
            }
        }
    }
